package com.zcc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object attribute = session.getAttribute("loginUser");
        if (attribute == null) {
            request.setAttribute("msg","未登录");
            request.getRequestDispatcher("/").forward(request, response);
            return false;
        }else {
            return true;
        }
    }
}
